package com.tac.service.impl;

import com.tac.common.R;
import com.tac.dao.SelectCourseDao;
import com.tac.dao.StudentDao;
import com.tac.pojo.SelectCourse;
import com.tac.pojo.SelectCourseDto;
import com.tac.pojo.Student;
import com.tac.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class StudentServiceImpl implements StudentService {
    @Autowired
    private StudentDao studentDao;
    @Autowired
    private SelectCourseDao selectCourseDao;
    @Override
    public List<Student> selectAll() {
        List<Student> students = studentDao.selectAll();
        return students;
    }

    /**
     * 删除学生
     * @param sid
     * @return
     */
    @Override
    public R delete(Integer sid) {
        List<SelectCourse> selectCourses = selectCourseDao.selectBysid(sid);
        if(selectCourses.size()>0){
            for (SelectCourse selectCourse:selectCourses){
                if(selectCourse.getStatus()==0){
                    return R.error("学生还有选课不能删除");
                }
            }
           studentDao.delete(sid);
            return R.success(null,"删除成功");
        }
        studentDao.delete(sid);
        return R.success(null,"删除成功");
    }
}
